<template>
    <div class="newsinfo_container">
        <!-- 文章头部 -->
        <div class="header">
            <h3>{{ newsinfo.title }}</h3>
            <p>
                <span>发布时间：{{newsinfo.add_time|dateFormat}}</span>
                <span>点击次数：{{newsinfo.click}}</span>
            </p>
            <hr>
        </div>
        <!-- 内容区域 -->
        <div class="content" v-html="newsinfo.content"></div>
        <!-- 评论子组件 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
// 引入评论子组件
import componentContent from "../subcomments/commentContent.vue";
export default {
    data() {
        return {
            id: this.$route.params.id,
            newsinfo: {}
        };
    },
    created() {
        this.getArticle();
    },
    methods: {
        getArticle() {
            this.$http.get("api/getnew/" + this.id).then(function(data) {
                if (data.body.status === 0) {
                    this.newsinfo = data.body.message[0];
                } else {
                    Toast("获取文章内容失败！");
                }
            });
        }
    },
    components: {
        "comment-box": componentContent
    }
};
</script>

<style lang="scss" >
.newsinfo_container {
    padding: 0 4px;
    .header {
        h3 {
            font-size: 14px;
            color: #333;
            text-align: center;
            line-height: 50px;
        }
        p {
            font-size: 12px;
            display: flex;
            justify-content: space-between;
        }
    }
    .content {
        img {
            width: 100%;
            height: auto;
        }
    }
}
</style>




